package mymac.com.a3_21;

import android.animation.ValueAnimator;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private ListView mMainList,mMenuList;
    private MyMainAdapter mainAdapter;
    private MyMenuAdapter menuAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mMainList = (ListView) findViewById(R.id.main_lv);
        mMenuList = (ListView) findViewById(R.id.menu_lv);
        mainAdapter = new MyMainAdapter();
        menuAdapter = new MyMenuAdapter();
        mMainList.setAdapter(mainAdapter);
        mMenuList.setAdapter(menuAdapter);
    }

    private class MyMainAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return 10;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View contentView;
            if (convertView == null){
                contentView = View.inflate(MainActivity.this,R.layout.list_menuitem,null);
            } else {
                contentView = convertView;
            }
            TextView textView = (TextView) contentView.findViewById(R.id.textView);
            textView.setText("MAIN " + position);
            textView.setTextColor(Color.BLACK);
            return contentView;
        }
    }

    private class MyMenuAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return 10;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            final View contentView;
            if (convertView == null){
                contentView = View.inflate(MainActivity.this,R.layout.list_menuitem,null);
            } else {
                contentView = convertView;
            }
            final TextView textView = (TextView) contentView.findViewById(R.id.textView);
            textView.setText("MENU " + position);
            final ValueAnimator animator = ValueAnimator.ofFloat(0.5f,1f);
            animator.setDuration(700).start();
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float values = (float) animator.getAnimatedValue();
                    contentView.setScaleX(values);
                    contentView.setScaleY(values);
                }
            });
            return contentView;
        }
    }
}
